<?php
require './wjinc/default/config.inc.php';
$sql = "SELECT * FROM wwk_chat_msg order by ID desc limit 100";
$sql = "SELECT * FROM (" . $sql . ") as ch order by ID asc";
$echo_msg = mysql_query($sql);
while($msg = mysql_fetch_array($echo_msg)) {
  $dataInfo[] = $msg;
}
$dataInfo = json_encode($dataInfo);

$userInfo = unserialize($_SESSION['member-session-name']);
$username = $userInfo['username'];
$chatUserInfo = mysql_query("SELECT * FROM wwk_chat_user WHERE username='{$username}'");
$chatUser = mysql_fetch_array($chatUserInfo);
$limitsql = mysql_query("select * from wwk_chat_user");
$limitinfo = mysql_fetch_array($limitsql);
if (!$chatUser) {
  if ($username) {
    $add_sql = "insert into wwk_chat_user values(null, '{$username}', '{$limitinfo['password']}', 0, '', '', '1', '1')";
    $result = mysql_query($add_sql);
    $user_info = mysql_query("SELECT * FROM wwk_chat_user WHERE username='{$username}'");
    $user = mysql_fetch_array($user_info);
  }else {
    exit;
  }
}

$user_info = mysql_query("SELECT * FROM wwk_chat_user WHERE username='{$username}'");
$user = mysql_fetch_array($user_info);

$user_vip = $user['vip'];
if ($user_vip == 1) {
  $vip_img = '/chatstatic/images/vip/icon_member1.gif';
} elseif ($user_vip == 2) {
  $vip_img = '/chatstatic/images/vip/icon_member2.gif';
} elseif ($user_vip == 3) {
  $vip_img = '/chatstatic/images/vip/icon_member3.gif';
} elseif ($user_vip == 4) {
  $vip_img = '/chatstatic/images/vip/icon_member4.gif';
} elseif ($user_vip == 5) {
  $vip_img = '/chatstatic/images/vip/icon_member5.gif';
} else {
  $vip_img = '/chatstatic/images/vip/icon_member6.gif';
}
$img_src  =  $user['img'];
$nickname = $user['nickname'];
//管理员
$admin = $user['type'];
// 是否可以聊天
$talk = $user['talk'];
// 聊天金额
$limit = $user['password'];
?>